<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button class="get">get</button>
    <button class="post">post</button>
</body>
<script type="module">

    import { ajax } from "../js/ajax.js";
    // import { $ } from "../js/myQuery.js";


    var getBtn = document.getElementsByClassName("get")[0];
    var postBtn = document.getElementsByClassName("post")[0];



    // ajax的请求流程
    // 1. 创建请求
    // 2. 配置请求相关的信息 type url async
    // 3. 发送请求  
    // 4. 绑定事件 -> 监听xhr.readyState改变 
    // 5. 接收服务器响应数据 => 后续处理


    getBtn.onclick = function () {
        var wd = "";  // 默认查询所有数据
        var col = "id"; //默认id排序
        var type = "asc"; //默认升序
        var page = 1; // 默认显示第一页
        var size = 10;  // 默认显示10条

        // http://43.138.81.225/demo/php/searchGoodsOrderLimit.php
        // `wd=${wd}&col=${col}&type=${type}&page=${page}&size=${size}`


        // get({
        //     url: "http://43.138.81.225/demo/php/searchGoodsOrderLimit.php",
        //     data: `wd=${wd}&col=${col}&type=${type}&page=${page}&size=${size}`,
        //     // async: true,
        //     dataType: "json",
        //     success: function (res) {
        //         console.log("请求成功", res);
        //     }
        // })

        ajax({
            type: "get",
            url: "http://43.138.81.225/demo/php/searchGoodsOrderLimit.php",
            data: {
                wd: wd,
                col,
                type,
                size,
                page
            },
            // async: true,
            dataType: "json",
            success: function (res) {
                console.log("请求成功", res);
            }
        })

        // $.ajax({
        //     type: "get",
        //     url: "http://43.138.81.225/demo/php/searchGoodsOrderLimit.php",
        //     data: {
        //         wd: wd,
        //         col,
        //         type,
        //         size,
        //         page
        //     },
        //     // async: true,
        //     dataType: "json",
        //     success: function (res) {
        //         console.log("请求成功", res);
        //     }
        // })

    }


    postBtn.onclick = function () {
        var user = "a123123";
        var pwd = "123123";
        var phone = 17386141517;
        var email = "a123123@163.com";

        // http://43.138.81.225/demo/php/register.php

        ajax({
            type: "post",
            url: "http://43.138.81.225/demo/php/register.php",
            data: {
                user,
                pwd,
                phone,
                email,
            },
            async: true,
            dataType: "json",
            success: function (res) {
                console.log("请求成功", res);
            }
        })

    }






</script>

</html>